// pages/home/scan/scan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    passStatus: '0',
    passResult: '0',
    temperature: "",
    healthStatus: '0',
    recordAddress: "",
    tripDesc: "",
    remarks: "",

    userInfo:{},
    sysUserInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      userInfo: getApp().globalData.userInfo
    })
    wx.showLoading({
      title: '加载中'
    });
    // 查询数据
    let _this = this;
    wx.request({
      url: getApp().globalData.BASE_URL + "/qrcode/analysis",
      data: {
        key: options.result
      },
      header: {
        'Authorization': getApp().globalData.TOKEN
      },
      success(res) {
        console.log(res.data)
        if (res.data.code == 200) {
          _this.setData({
            sysUserInfo: res.data.data
          })
        } else {
          wx.showModal({
            title: '扫描提示',
            showCancel: false,
            content: res.data.msg,
            success(res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '../index/index',
                })
              }
            }
          })
        }
        wx.hideLoading();
      }

    })
  },
  submitInfo(){
    if(this.data.temperature==""){
      wx.showToast({
        title: '测量体温是必填',
        icon: 'none',
        duration: 1500
      });
      return;
    }
    if (this.data.recordAddress == "") {
      wx.showToast({
        title: '检测地点是必填',
        icon: 'none',
        duration: 1500
      });
      return;
    }
    
    wx.showLoading({
      title: '加载中',
    });
    // 提交数据
    let _this = this;
    wx.request({
      url: getApp().globalData.BASE_URL + "/health/record/wx",
      method: "POST",
      header: {
        'Authorization': getApp().globalData.TOKEN
      },
      data: {
        userId: _this.data.sysUserInfo.userId,
        adminId: _this.data.userInfo.adminId,
        passStatus: _this.data.passStatus,
        passResult: _this.data.passResult,
        temperature: _this.data.temperature,
        healthStatus: _this.data.healthStatus,
        recordAddress: _this.data.recordAddress,
        tripDesc: _this.data.tripDesc,
        remarks: _this.data.remarks
      },
      success(res) {
        console.log(res.data)
        wx.showModal({
          title: '提交提示',
          showCancel: false,
          content: res.data.msg,
          success(res) {
            if (res.confirm) {
              wx.switchTab({
                url: '../index/index',
              })
            }
          }
        })
        wx.hideLoading();
      }

    })
  },

  changeRecordAddress(event){
    this.setData({
      recordAddress: event.detail,
    });
  },
  changeTemperature(event){
    this.setData({
      temperature: event.detail,
    });
  },

  onChangePassStatus(event) {
    this.setData({
      passStatus: event.detail,
    });
  },

  onChangePassResult(event) {
    this.setData({
      passResult: event.detail,
    });
  },

  onChangeHealthStatus(event) {
    this.setData({
      healthStatus: event.detail,
    });
  },

  onChangeTripDesc(event) {
    this.setData({
      tripDesc: event.detail.value,
    });
  },
  onChangeRemarks(event) {
    this.setData({
      remarks: event.detail.value,
    });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})